<?php 


include './Http.class.php';


// // $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
// $c=urlencode('北京');
// var_dump($c);
// die;
                 $keyword=urlencode('北京');
                 // $keyword=iconv("UTF-8", "GB2312//IGNORE",'北京');
                 $url = "https://api.seniverse.com/v3/weather/daily.json?key=yp9rc5pp0kvxgrdj&location=".$keyword ."&language=zh-Hans&unit=c&start=0&days=5";
              
                 // $url = "https://api.seniverse.com/v3/weather/daily.json?key=yp9rc5pp0kvxgrdj&location=北京&language=zh-Hans&unit=c&start=0&days=5";
                  // $url = "https://www.baidu.com";
                   // $url = "www.baidu.com";
                 $resData = Http::get($url);
                  var_dump($resData);
                 die;
                 $res = json_decode($resData, true);
                 var_dump($res);
                 die;
                if(isset($res['results'][0]['daily']) && !empty($res['results'][0]['daily']))
                {
                    $str = "<xml>
                            <ToUserName><![CDATA[%s]]></ToUserName>
                            <FromUserName><![CDATA[%s]]></FromUserName>
                            <CreateTime>%s</CreateTime>
                            <MsgType><![CDATA[news]]></MsgType>
                            <ArticleCount>7</ArticleCount>
                            <Articles>";

                    foreach ($res['results'][0]['daily'] as $key => $val) {
                        $WetherTurn='';
                        if($val['text_day']==$val['text_night'])
                        {
                            $WetherTurn=$val['text_day'];
                        }else{
                            $WetherTurn=$val['text_day']." 转 ".$val['text_night'];
                        }

                        $str .= "<item>
                        <Title><![CDATA[".$keyword." ".$val['date'].' '.$WetherTurn.' 最高温度 '.$val['high'].' 最低温度 '.$val['low'] . $val['wind_direction'].'风，风速'.$val['wind_scale'].'级 风速'.$val['wind_speed'].'km/h' . "]]></Title> 
                        <Description><![CDATA[description1]]></Description>
                        <PicUrl><![CDATA[http://files.heweather.com/cond_icon/".$val['cond']['code_d'].".png]]></PicUrl>
                        <Url><![CDATA[www.baidu.com]]></Url>
                        </item>";
                    }

                    $str .= "</Articles>
                        </xml>";   
                }else
                {
                    
                     }

 ?>